#!/bin/sh

#
# Test that signing doesn't change the firmware's uuid
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"

EXPECTED_OUTPUT=$WORK/expected_output
ACTUAL_OUTPUT=$WORK/actual_output

cat >$CONFIG <<EOF
meta-product = "product name"
meta-description = "product description"
meta-version = "some version"
meta-platform = "a platform"
meta-architecture = "an architecture"
meta-author = "someone"
EOF

cat >$EXPECTED_OUTPUT <<EOF
meta-product="product name"
meta-description="product description"
meta-version="some version"
meta-author="someone"
meta-platform="a platform"
meta-architecture="an architecture"
meta-creation-date="2018-05-05T18:10:16Z"
meta-uuid="ded51581-3c37-5dd5-d1b6-cd8503e4cfc4"
EOF

cd $WORK
$FWUP_CREATE -g
cd -
SOURCE_DATE_EPOCH=1525543816 $FWUP_CREATE -c -f $CONFIG -o $FWFILE

# Sanity check that unsigned version passes (this should already work)
$FWUP_APPLY_NO_CHECK -i $FWFILE -m > $ACTUAL_OUTPUT
diff -w $EXPECTED_OUTPUT $ACTUAL_OUTPUT

# Sign the archive
SOURCE_DATE_EPOCH=1525543816 $FWUP_CREATE -S -s $WORK/fwup-key.priv -i $FWFILE -o $FWFILE.2

# Check the metadata again (meta-uuid shouldn't change)
$FWUP_APPLY_NO_CHECK -i $FWFILE.2 -m > $ACTUAL_OUTPUT
diff -w $EXPECTED_OUTPUT $ACTUAL_OUTPUT
